<?php
session_start();
require_once '../data/connect.class.php';
require_once "../securimage/securimage.php";
$data = "";
ECHO $_POST['code'];
$img = new Securimage();
$valid = $img->check($_POST['code']);

if($valid != true) {
    $data = "<center>Sorry, the code you entered was invalid.  <a href=\"javascript:history.go(-1)\">Go back</a> to try again.</center>";
} else {
	$connect = new Connect("localhost","root","","email");


	$addrId = $_REQUEST['addrId'];
	
	$encodedContent = $_REQUEST['encodedContent'];
	
	$decodedContent = urldecode($encodedContent);
	
	$array = array("subcripted"=>0);
	$connect->updateSql("admin_mail_addr",$array,"id=".$addrId);
	
	$sql = "select name, mail_addr from admin_mail_addr where id=".$addrId;
	$resultSet = $connect->Query($sql);
	$addrName = $resultSet[0]['name'];
	$addr = $resultSet[0]['mail_addr'];
	$insertArray = array("reason"=>$decodedContent,"addr_name"=>$addrName,"addr"=>$addr);
	$connect->insertSql("admin_unsubscripted",$insertArray);
	
	$data = "成功";
}

echo $data;

?>